import MarkdownIt from "markdown-it";

export default {
    name: 'ChatMessage',
    props: {

        rawData: {
            type: Object,
            required: true,
            default: () => ({})
        },
        sendLoading: {
            type: Boolean,
            required: true,
            default: false
        },
    },
    data() {
        return {
            activeTab: 'export',
            md: null,
            localSearchDisplay: '',
            localAnswer: ''
        }
    },
    created() {
        // 初始化markdown-it
    this.md = new MarkdownIt();
    },
    methods: {
        rederMessage() {

        },
        clearLocalData() {
            this.localSearchDisplay = '';
            this.localAnswer = '';
        },
        renderMarkdown(text) {
            if (!text) return '';
            return this.md.render(text);
        }
    },
    watch: {
        sendLoading: {
            handler(newVal) {
                if (newVal) {
                    // 当开始新的请求时，清空本地数据
                    this.clearLocalData();
                }
            }
        },
        'rawData.search_display': {
            handler(newVal) {
                if (newVal) {
                    this.localSearchDisplay = newVal;
                }
            }
        },
        'rawData.answer': {
            handler(newVal) {
                if (newVal) {
                    this.localAnswer = newVal;
                }
            }
        },

    }
}